//
//  BPUICommonDefines.h
//  BPUIKit
//
//  Created by 404 on 2020/7/30.
//  Copyright © 2020 404. All rights reserved.
//

#import <mach/mach_time.h>

#ifndef BPUICommonDefines_h
#define BPUICommonDefines_h

/// 屏幕宽度，会根据横竖屏的变化而变化
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)

/// 屏幕高度，会根据横竖屏的变化而变化
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)

/// 设备宽度，跟横竖屏无关
#define DEVICE_WIDTH MIN([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)

/// 设备高度，跟横竖屏无关
#define DEVICE_HEIGHT MAX([[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)

/// 状态栏高度(来电等情况下，状态栏高度会发生变化，所以应该实时计算，iOS 13 起，来电等情况下状态栏高度不会改变)
#define StatusBarHeight (UIApplication.sharedApplication.statusBarHidden ? 0 : UIApplication.sharedApplication.statusBarFrame.size.height)

/// 是否有刘海
#define IS_NotchedScreen \
({BOOL isNotchedScreen = NO;\
if (@available(iOS 11.0, *)) {\
isNotchedScreen = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isNotchedScreen);})

#define STATUS_HEIGHT  ((IS_NotchedScreen) ? (44.0):(20.0))

/// 底部安全区域高度
#define SafeAreaBottomHeight (IS_NotchedScreen ? 34.0f : 0.0f)
/// 顶部导航栏高度常量
#define SafeAreaTopConstant (IS_NotchedScreen ? 88 : 64)
/// 底部tabbar高度常量
#define TabbarBottonConstant (49 + SafeAreaBottomHeight)

/// bounds && nativeBounds / scale && nativeScale
#define ScreenBoundsSize ([[UIScreen mainScreen] bounds].size)
#define ScreenNativeBoundsSize ([[UIScreen mainScreen] nativeBounds].size)
#define ScreenScale ([[UIScreen mainScreen] scale])
#define ScreenNativeScale ([[UIScreen mainScreen] nativeScale])

#pragma mark - 方法 创建器

#define UIImageMake(img) [UIImage imageNamed:img]

/// 使用文件名(不带后缀名，仅限png)创建一个UIImage对象，不会被系统缓存，用于不被复用的图片，特别是大图
#define UIImageMakeWithFile(name) UIImageMakeWithFileAndSuffix(name, @"png")
#define UIImageMakeWithFileAndSuffix(name, suffix) [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", [[NSBundle mainBundle] resourcePath], name, suffix]]

#define UIImageMakeWithStoreKitFile(name) UIImageMakeWithFileAndSuffixInBPStoreKit(name,@"png")

#define UIImageMakeWithFileAndSuffixInBundle(name, suffix, bundle) [UIImage imageWithContentsOfFile:[NSString filePathWithFile:[name stringByAppendingPathExtension:suffix] inBundle:bundle]]

/// 字体相关的宏，用于快速创建一个字体对象
#define UIFontMake(size) [UIFont systemFontOfSize:size]
#define UIFontItalicMake(size) [UIFont italicSystemFontOfSize:size] /// 斜体只对数字和字母有效，中文无效
#define UIFontBoldMake(size) [UIFont boldSystemFontOfSize:size]
#define UIFontBoldWithFont(_font) [UIFont boldSystemFontOfSize:_font.pointSize]

/// UIColor 相关的宏，用于快速创建一个 UIColor 对象
#define UIColorMake(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define UIColorMakeWithRGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/1.0]

#define ColorWithHexValue(hexValue, a) [UIColor colorWithRed:((hexValue >> 16) & 0x000000FF)/255.0f green:((hexValue >> 8) & 0x000000FF)/255.0f blue:((hexValue) & 0x000000FF)/255.0f alpha:a]


#pragma mark - UserDefaults
/// 回主线程
#define MAINBLOCK(block) dispatch_async(dispatch_get_main_queue(),block)


#define DEFAULTS [NSUserDefaults standardUserDefaults]

#pragma mark - Path

CG_INLINE NSString*

NSCachePath() {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return paths.firstObject;
}


#pragma mark - 其他
#define StringFromBOOL(_flag) (_flag ? @"YES" : @"NO")

/// debug环境Log输出
#ifdef DEBUG
#define XHJLog(fmt, ...) NSLog((@"\r\n=====================分割线=======================\n%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define XHJLog(...)
#endif


#endif /* BPUICommonDefines_h */
